package com.wyj.rpc.controller;

import com.wyj.rpc.config.RpcClient;
import com.wyj.rpc.config.RpcServiceProxy;
import com.wyj.rpc.pojo.Order;
import com.wyj.rpc.service.IOrderService;
import com.wyj.rpc.service.IUserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {

    IOrderService orderService;

    @PostConstruct
    public void init() {
        orderService = (IOrderService) RpcServiceProxy.createProxy(IOrderService.class);
    }

    @GetMapping(value = "/{id}")
    public Order order(@PathVariable Integer id) {
        return orderService.findById(id);
    }

    @GetMapping(value = "/orders/{userId}")
    public List<Order> orders(@PathVariable Integer userId) {
        return orderService.findListByUserId(userId);
    }

}
